package com.cqndt.site.controller;

import com.cqndt.site.entity.TabJournalRecord;
import com.cqndt.site.service.back.TabJournalRecordService;
import com.cqndt.site.util.Result;
import com.cqndt.site.vo.ConditionVo;
import com.cqndt.site.vo.RecordDetailVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * Description:月刊记录
 */
@RestController
@RequestMapping("record")
public class TabJournalRecordController extends AbstractController{

    @Autowired
    private TabJournalRecordService recordService;

    @ApiOperation("获取期刊记录")
    @PostMapping(value="list")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Integer", name = "periodNum", value = "期数", defaultValue = "", paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "startTime", value = "开始时间", defaultValue = "", paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "endTime", value = "结束时间", defaultValue = "", paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "releaseAccount", value = "发布账号", defaultValue = "", paramType = "query"),
            @ApiImplicitParam(dataType = "Integer", name = "page", value = "页数", defaultValue = "1", paramType = "query"),
            @ApiImplicitParam(dataType = "Integer", name = "limit", value = "每页条数", defaultValue = "10", paramType = "query")
    })
    public Result listRecord(ConditionVo vo) {
        //vo.setReleaseAccount(getUser().getUserName());
        vo.setLoginAccount("admin");
        PageHelper.startPage(vo.getPage(),vo.getLimit());
        PageInfo<TabJournalRecord> pageInfo = new PageInfo<TabJournalRecord>(recordService.listRecords(vo));
        Result result = new Result();
        result.setCount((int)pageInfo.getTotal());
        result.setData(pageInfo.getList());
        return result;
    }

    @ApiOperation("期刊记录中点击编辑获取期刊详情")
    @PostMapping(value="getRecordById")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Integer", name = "id", value = "期刊记录id", defaultValue = "", paramType = "query")
    })
    public Result getRecordById(Integer id) {
        return recordService.getRecordById(id);
    }

    @ApiOperation("期刊记录中点击删除记录")
    @PostMapping(value="delRecordById")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Integer", name = "id", value = "期刊记录id", defaultValue = "", paramType = "query")
    })
    public Result delRecordById(Integer id) {
        return recordService.delRecordById(id);
    }

    @ApiOperation("期刊编辑")
    @PostMapping(value="editRecord")
    public Result editRecord() {
        //String loginAccount = getUser().getUserName();
        String loginAccount = "admin";
        return recordService.editRecord(loginAccount);
    }

    @ApiOperation("期刊保存或发布")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Integer", name = "releaseState", value = "操作按钮：1保存 2发布", defaultValue = "", paramType = "query")
    })
    @PostMapping(value="addOrReleaseRecord")
//    public Result addOrReleaseRecord(HttpServletRequest request) {
    public Result addOrReleaseRecord(@RequestBody RecordDetailVo vo) {
        //String loginAccount = getUser().getUserName();
        String loginAccount = "admin";
//        String releaseState = request.getParameter("releaseState");
//        String record = request.getParameter("record");
//        String tabGuide = request.getParameter("tabGuide");
//        String tabContryTrend = request.getParameter("tabContryTrend");
//        String tabProvinceTrend = request.getParameter("tabProvinceTrend");
//        String tabIndustryTrend = request.getParameter("tabIndustryTrend");
//        String tabTendering = request.getParameter("tabTendering");
//        String tabWinbid = request.getParameter("tabWinbid");
//        String tabCompeteAnalysis = request.getParameter("tabCompeteAnalysis");

//        return recordService.addOrReleaseRecord(releaseState,loginAccount,record,tabGuide,tabContryTrend,tabProvinceTrend,
////                tabIndustryTrend,tabTendering,tabWinbid,tabCompeteAnalysis);
        return recordService.addOrReleaseRecord(loginAccount,vo);
    }


}
